#define _CRT_SECURE_NO_WARNINGS 1
//https://www.luogu.com.cn/problem/P1113
#include<iostream>
#include<vector>
#include<queue>

using namespace std;

const int N = 10010;

int n;
vector<int>edges[N];
int in[N], dp[N];
int len[N];
int main()
{
	cin >> n;
	for (int i = 1;i <= n;i++)
	{
		int a = 0, b = 0;
		cin >> b >> len[b];
		while (cin >> a, a)
		{
			edges[a].push_back(b);
			in[b]++;
		}
	}

	queue<int>q;
	for (int i = 1;i <= n;i++)
	{
		if (!in[i])
			q.push(i);
	}

	int ret = 0;
	while (q.size())
	{
		int a = q.front();
		q.pop();
		dp[a] += len[a];
		ret = max(ret, dp[a]);
		for (auto& b : edges[a])
		{
			dp[b] = max(dp[b], dp[a]);
			in[b]--;
			if (!in[b])
				q.push(b);
		}
	}

	cout << ret;
	return 0;
}